package com.hfkh.keyun.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
public class AppConfig implements WebMvcConfigurer {

    // windows操作系统图片存储路径
    @Value("${web.windows.upload-path}")
    private String windowsSavePath;

    // linux操作系统图片存储路径
    @Value("${web.linux.upload-path}")
    private String linuxSavePath;

    // 对外访问的资源路径
    @Value("${web.static-access-path}")
    private String staticAccessPath;

    @Resource
    private Environment env;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String osName = env.getProperty("os.name");
        String picPath = "";
        if(osName.contains("Windows")) {
            picPath = windowsSavePath;
        }
        else {
            picPath = linuxSavePath;
        }
        System.out.println("picPath:>>>>>>>>>>>>>>" + picPath);
        registry.addResourceHandler(staticAccessPath)
                .addResourceLocations("file:///" + picPath);
    }
}
